Skip to content

🤖 refactor: auto-cleanup#3291

Open
mux-bot[bot] wants to merge 4 commits into
mainfrom
auto-cleanup
Open

🤖 refactor: auto-cleanup#3291
mux-bot[bot] wants to merge 4 commits into
mainfrom
auto-cleanup

Conversation

@mux-bot
Copy link
Copy Markdown
Contributor

@mux-bot mux-bot Bot commented May 15, 2026

Summary

Rolling, low-risk cleanup batch. Each run adds one extremely small,
behavior-preserving refactor picked from changes that have landed on main
since the last checkpoint.

Current diff against main:

  • src/browser/features/Messages/Mermaid.tsx — hoist the URL-attribute
    set and blocked-scheme list out of sanitizeMermaidSvg into
    module-level constants (SANITIZER_URL_ATTRIBUTES,
    SANITIZER_BLOCKED_URL_SCHEMES). They are pure lookup data with no
    per-call dependency, so allocating them on every Mermaid render was
    wasted work; they now allocate once per module load. Identical
    contents and identical lookup semantics — pure cleanup with no
    behavior change.

  • src/node/services/agentStatusService.ts — hoist the AI SDK v5
    tool-part state → lifecycle phase mapping out of summarizeToolPart
    into a module-level TOOL_PART_PHASE_BY_STATE record. The previous
    nested ternary obscured the actual mapping (output-available and
    output-redacted both fold to "done") and made adding new states a
    multi-line edit. The summarizer now does a single table lookup; the
    union-typed values document the two valid phases inline. States not
    in the table (e.g. input-streaming) still yield null and the bare
    [tool <name>] form, byte-for-byte identical to before.

  • src/browser/utils/slashCommands/experimentVisibility.ts (+ two
    consumers) — add createSlashCommandExperimentResolver(snapshot)
    alongside resolveSlashCommandExperimentValue. Three slash-command
    discovery surfaces (suggestions in ChatInput, the ghost-hint call in
    ChatInput, and the CommandPalette palette query) had each inlined
    the same (experimentId) => resolveSlashCommandExperimentValue(experimentId, { goals, workspaceHeartbeats }) lambda. The new helper returns the
    exact same closure each callsite previously built inline, so the
    isExperimentEnabled predicate handed to getSlashCommandSuggestions
    / getCommandGhostHint is behaviorally identical; only the wiring
    detail (that resolution is parameterized by experiment id) moves into
    the visibility module.

Validation

  • make static-check — eslint, tsgo (×2 configs), and prettier all green
    locally; the only red step is fmt-shell-check failing because shfmt
    isn't installed in this environment (pre-existing env limitation, no
    shell files touched by these changes).
  • bun test src/browser/features/Messages/Mermaid.test.tsx — 12/12
    pass, including the recent foreignObject/<br> sanitizer regression
    tests and the existing security-relevant cases (<script>,
    on* handlers, javascript: hrefs).
  • bun test src/node/services/agentStatusService.test.ts src/node/services/workspaceStatusGenerator.test.ts
    — 34/34 pass, including the tool-part lifecycle tests that key on the
    running/done suffixes the refactored lookup produces.
  • bun test src/browser/utils/slashCommands/suggestions.test.ts src/browser/utils/slashCommands/ghostHint.test.ts
    — 27/27 pass, covering the experiment-gated visibility branches the
    new helper feeds.
  • bun test src/browser/components/CommandPalette/CommandPalette.test.ts src/browser/features/ChatInput/CommandSuggestions.test.tsx
    — 16/16 pass, exercising the palette/suggestion rendering paths whose
    isExperimentEnabled wiring changed.

Risks

Negligible — all three changes are pure local hoisting / factory
extraction inside the same module. Allow/deny lists, the state→phase
mapping, and the experiment-resolver closure are byte-identical to the
inline versions; only their allocation site moved.

Process

Auto-cleanup checkpoint: 8f91862


Generated with mux • Model: anthropic:claude-opus-4-7 • Thinking: xhigh • Cost: $

@mux-bot mux-bot Bot force-pushed the auto-cleanup branch 2 times, most recently from dc0bbfe to 69d4d25 Compare May 16, 2026 20:19
mux-bot Bot and others added 4 commits May 17, 2026 00:20
Both image_generate and image_edit duplicated the same
"Adjust Settings > Experiments > Image Tools or request fewer
images." setup hint literal when the requested image count
exceeded the configured maxImagesPerCall. Hoist it next to the
existing IMAGE_TOOL_PROVIDER_SETUP_HINT in imageArtifacts.ts so
the guidance has a single source of truth, matching the pattern
established by the prior auto-cleanup PR.
Move `urlAttributes`/`blockedSchemes` out of `sanitizeMermaidSvg` and
into module-level constants (`SANITIZER_URL_ATTRIBUTES`,
`SANITIZER_BLOCKED_URL_SCHEMES`). They are pure lookup data with no
per-call dependency, so allocating them on every render of every Mermaid
diagram was wasted work — these now allocate once per module load.

Pure cleanup: identical contents, identical lookup semantics, no
behavior change. The full Mermaid.test.tsx suite (including the recent
sanitizer regression tests) still passes.

---

_Generated with `mux` • Model: `anthropic:claude-opus-4-7` • Thinking: `xhigh` • Cost: `$`_

<!-- mux-attribution: model=anthropic:claude-opus-4-7 thinking=xhigh costs= -->
`summarizeToolPart` carried the AI SDK v5 `state` → lifecycle phase
mapping inline as a nested ternary plus a multi-line comment listing the
states. The ternary obscured the actual mapping (output-available and
output-redacted both fold to "done") and made adding new states a
multi-line edit.

Hoist the mapping to a `TOOL_PART_PHASE_BY_STATE` record at module
scope, keyed on the SDK state strings and typed as the literal phase
union. The summarizer now does a single table lookup. States not in the
table (e.g. `input-streaming`) still yield `null` and the bare
`[tool <name>]` form, matching prior behavior exactly.

Behavior-preserving: same input strings, same output bytes for every
`state` value the prior code handled, and the same `null` fallthrough
for everything else.
Three slash-command discovery surfaces (suggestions in ChatInput, ghost
hints in ChatInput, and CommandPalette) duplicated the same inline
lambda:

  (experimentId) =>
    resolveSlashCommandExperimentValue(experimentId, {
      goals: goalsExperimentEnabled,
      workspaceHeartbeats: workspaceHeartbeatsExperimentEnabled,
    })

Add createSlashCommandExperimentResolver(snapshot) next to its sibling
resolver so each callsite only describes the experiment snapshot it
observes. The new helper returns the exact same closure each callsite
previously built inline, so behavior is byte-identical.
@mux-bot mux-bot Bot force-pushed the auto-cleanup branch from 69d4d25 to f810665 Compare May 17, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant